package com.example.demo03_mvm.view;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ToastUtils;
import com.example.demo03_mvm.R;
import com.example.demo03_mvm.databinding.ActivityRegisterBinding;
import com.example.demo03_mvm.viewmodel.UserViewModel;
import com.google.android.material.textfield.TextInputEditText;

import java.util.HashMap;

@Route(path = "/app/RegisterActivity")
public class RegisterActivity extends BaseActivity<UserViewModel, ActivityRegisterBinding> {
    TextInputEditText et_name,et_pass,et_pass2;
    @Override
    protected int inflateLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initData() {
        db.btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = et_name.getText().toString();
                String pass = et_pass.getText().toString();
                String pass2 = et_pass2.getText().toString();
                if(name.isEmpty()||pass.isEmpty()||pass2.isEmpty()){
                    ToastUtils.showLong("输入内容都不能为空");
                    return;
                }
                if(!name.matches("[A-z0-9_]{5,10}")){
                    ToastUtils.showLong("格式不正确");
                    return;
                }
                HashMap<String, String> map = new HashMap<>();
                map.put("username",name);
                map.put("password",pass);
                map.put("repassword",pass2);
                vm.register(map,RegisterActivity.this);
            }
        });
    }

    @Override
    protected void initView() {
        et_name=db.etName;
        et_pass=db.etPass;
        et_pass2=db.etPass2;
    }
}